import { WidgetOption, WidgetStyle, WidgetType } from '@/types'
import WidgetCheckbox from './WidgetCheckbox.vue'
import CheckboxFill from './CheckboxFill.vue'

export default {
  key: 'checkbox',
  name: '勾选框',
  type: WidgetType.CHECKBOX,
  style: WidgetStyle.FILL,
  icon: 'fa-icon-widget-checkbox',
  width: 16,
  height: 16,
  default: {
    value: true
  },
  component: WidgetCheckbox,
  fillingComponent: CheckboxFill,

  // 初始值为布尔值
  init(widget, data) {
    let { value } = data
    const values = {
      true: true,
      false: false
    }

    widget.value = (values[value as keyof typeof values] ?? !!value) as unknown as string
  },

  usingValidate(widget) {
    if (widget.required && !widget.hasFillValue) return `请勾选${widget.displayName}`
  }
} as WidgetOption
